<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<button onclick="getMessage()">按钮</button>
</body>

<script >
    function getMessage() {
        //实列化一个xmlhttprequest
        var reuquest = new XMLHttpRequest();
        //设置xml对象的回调函数
        reuquest.onreadystatechange = function () {
            if (reuquest.status==200&& reuquest.readyState==4){
                console.log(reuquest.responseText)
            }
        }
        //设置发送请求的方式和请求资源路径
        reuquest.open('GET','http://localhost:8080/hello?username=zhangsan')
        //发送请求
        reuquest.send()
    }

</script>
</html>